package com.qfmy.mystation.ui.fragment;

import static android.content.Context.CLIPBOARD_SERVICE;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.qfmy.mystation.BuildConfig;
import com.qfmy.mystation.databinding.FragmentAboutBinding;
import com.qfmy.mystation.utils.ToastUtils;

public class AboutFragment extends Fragment {
    private final String GITEE_URL = "https://gitee.com/ybmzwl/MyStation";
    private FragmentAboutBinding binding;


    public static AboutFragment newInstance() {
        return new AboutFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentAboutBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding.tvBlog.setOnClickListener(view1 -> ToastUtils.shortToast("这里什么也没有..."));
        binding.tvCode.setOnClickListener(view1 -> jumpUrl(GITEE_URL));
        binding.tvCopyEmail.setOnClickListener(v -> copyEmail());
        binding.tvAuthor.setOnClickListener(view1 -> ToastUtils.shortToast("你为啥要点我呢？"));
        binding.tvVersion.setText(BuildConfig.VERSION_NAME);
    }

    private void jumpUrl(String url) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    }

    private void copyEmail() {
        ClipboardManager myClipboard = (ClipboardManager) requireContext().getSystemService(CLIPBOARD_SERVICE);
        ClipData myClip = ClipData.newPlainText("text", "3139172123@qq.com");
        myClipboard.setPrimaryClip(myClip);
        ToastUtils.shortToast("邮箱已复制");
    }
}